﻿using System;
using System.Collections.Generic;
using System.Security.Principal;

using Moe.ECamel.Common.Contracts;

namespace Moe.ECamel.Common.Security
{
	/// <summary>
	/// Security principal implementation for ECamel, providing authorization services.
	/// </summary>
	public class ECamelPrincipal : GenericPrincipal
	{
		private readonly HashSet<String> _operations;

		public static readonly ECamelPrincipal Empty = new ECamelPrincipal(new LoginResponse {Username = "אורח"});

		public ECamelPrincipal(LoginResponse loginResponse)
			: this(new ECamelIdentity(loginResponse.Username), loginResponse)
		{
		}
		private ECamelPrincipal(IIdentity identity, LoginResponse loginResponse)
			: base(identity, null)
		{
			this._operations = loginResponse.Operations;
		}

		public override bool IsInRole(string role)
		{
			return _operations.Contains(role);
		}
	}
}